package com.app.utils;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;

import java.util.Collections;

public class AutoCodeCreateUtil {
    public static void main(String[] args) {
        DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(
                "jdbc:mysql://localhost:3306/test?serverTimezone=UTC",
                "root",
                "123456")
                .build();

        //配置全局信息
         GlobalConfig globalConfig = new GlobalConfig.Builder()
                .fileOverride()
                .outputDir("D:\\IDEASpace\\WorkSpace\\zqb2001\\src\\main\\java")
                .author("")
                .enableSwagger()
                .dateType(DateType.TIME_PACK)
                .commentDate("yyyy-MM-dd")
                .build();


        //配置包的信息
         PackageConfig packgeConfig = new PackageConfig.Builder()
                .parent("com")
                .moduleName("app")
                .entity("pojo")
                .service("service")
                .serviceImpl("service.impl")
                .mapper("mapper")
                .xml("mapper.xml")
                .controller("ctrl")
                .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\IDEASpace\\WorkSpace\\zqb2001\\src\\main\\resources\\mapper"))
                .build();


        //创建执行类
        AutoGenerator generator = new AutoGenerator(dataSourceConfig);
        generator.global(globalConfig);
        generator.packageInfo(packgeConfig);
        //调用这个自动生成代码的执行类的执行方法
        generator.execute();



    }
}
